package com.asialjim.wechat.official.authpage;

import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletResponse;

/**
 * <h1><em>ASIAL JIM JAVA DOC</em></h1><hr/>
 * <h2>CLASS DESCRIPTION <i>[ NAME: AutuPageController ]</i></h2><strong>
 * <p> auth page controller
 * </strong><p><p><em>Copyright &copy; Asial Jim Co., LTD</em><hr/>
 *
 * @author Asial Jim &nbsp;&nbsp; <span>Email:<a href="mailto:asialjim@hotmail.com">asialjim@hotmail.com</a> &nbsp;&nbsp; <a href="asialjim@qq.com">asialjim@qq.com</a></span>
 * @version 1.0.0
 * @since 2021/4/5   &nbsp;&nbsp; JDK 8
 */
@Controller
@AllArgsConstructor
@RequestMapping("/official/authpage")
public class AuthPageController {
    private final AuthPageService pageService;

    @SneakyThrows
    @GetMapping("/redirect")
    public void redirect(String code, String state, HttpServletResponse response){
        String url = pageService.redirectUrl(code, state);
        response.sendRedirect(url);
    }

    @PostMapping("/add")
    public AuthPage add(@RequestBody AuthPage authPage){
        return pageService.addAuthPage(authPage);
    }
}
